package com.zy.openchat.core.model.group;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.core.model.message.ChatInfo;
import com.zy.openchat.core.model.message.ChatType;
import com.zy.openchat.core.model.photo.ProfilePhoto;

import java.util.ArrayList;
import java.util.List;

public class ChatInviteLink implements Parcelable {

    public String invite_link;
    public int accessible_for;
    public ChatType type;
    public long chat_id;
    public String title;
    public ProfilePhoto photo;
    public int member_count;
    public List<Long> member_user_ids;
    public boolean is_public;

    public ChatInfo chatInfo;


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.invite_link);
        dest.writeInt(this.accessible_for);
        dest.writeParcelable(this.type, flags);
        dest.writeLong(this.chat_id);
        dest.writeString(this.title);
        dest.writeParcelable(this.photo, flags);
        dest.writeInt(this.member_count);
        dest.writeList(this.member_user_ids);
        dest.writeByte(this.is_public ? (byte) 1 : (byte) 0);
    }

    public void readFromParcel(Parcel source) {
        this.invite_link = source.readString();
        this.accessible_for = source.readInt();
        this.type = source.readParcelable(ChatType.class.getClassLoader());
        this.chat_id = source.readLong();
        this.title = source.readString();
        this.photo = source.readParcelable(ProfilePhoto.class.getClassLoader());
        this.member_count = source.readInt();
        this.member_user_ids = new ArrayList<Long>();
        source.readList(this.member_user_ids, Long.class.getClassLoader());
        this.is_public = source.readByte() != 0;
    }

    public ChatInviteLink() {
    }

    protected ChatInviteLink(Parcel in) {
        this.invite_link = in.readString();
        this.accessible_for = in.readInt();
        this.type = in.readParcelable(ChatType.class.getClassLoader());
        this.chat_id = in.readLong();
        this.title = in.readString();
        this.photo = in.readParcelable(ProfilePhoto.class.getClassLoader());
        this.member_count = in.readInt();
        this.member_user_ids = new ArrayList<Long>();
        in.readList(this.member_user_ids, Long.class.getClassLoader());
        this.is_public = in.readByte() != 0;
    }

    public static final Creator<ChatInviteLink> CREATOR = new Creator<ChatInviteLink>() {
        @Override
        public ChatInviteLink createFromParcel(Parcel source) {
            return new ChatInviteLink(source);
        }

        @Override
        public ChatInviteLink[] newArray(int size) {
            return new ChatInviteLink[size];
        }
    };
}
